﻿using System;
using System.Collections.Generic;
using System.Linq.Expressions;
using System.Linq.Dynamic;

namespace Fuse8.DomainFramework.Common
{
    /// <summary>
    /// 
    /// </summary>
    public static class ExpressionUtility
    {
        /// <summary>
        /// 
        /// </summary>
        /// <param name="expression"></param>
        /// <returns></returns>
        public static IList<string> TryEvaluate(Expression expression)
        {
            List<string> result = new List<string>();

            string parameters = null;

            var resultExpression = Evaluator.PartialEval(expression, out parameters);

            if (!string.IsNullOrEmpty(parameters))
            {
                result.AddRange(parameters.Split(new string[] { "|" }, StringSplitOptions.RemoveEmptyEntries));
            }

            return result;
        }
    }
}
